package com.mmc.controller;

import com.mmc.entity.LoginUser;
import com.mmc.entity.User;
import com.mmc.result.R;
import com.mmc.service.IUserService;
import com.mmc.service.TokenService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 作者：李嘉浩
 * 时间：2024-09-13-17:02
 * 功能：
 */
@RestController
@Api(tags = "登录")
@RequestMapping("/admin/user")
public class UserLoginController {

    @Autowired
    private IUserService iUserService;

    @Autowired
    private TokenService tokenService;

    @PostMapping("/login")
    @ApiOperation("账号密码登录")
    public R login(@RequestBody User user){
        LoginUser loginuser=iUserService.login(user);
        Map<String, Object> token = tokenService.createToken(loginuser);
        return R.ok().data(token);
    }
}
